<!doctype  html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
	<title>学术竞赛</title>
<style type="text/css">
       body{
               background: url("image/6_bg.png");
               background-size: 100% 100%;
               background-repeat: no-repeat;
               min-height:800px;
               width: 100%;
               padding-bottom:30px;
       }
       form{
       	margin: 0 auto;
       	margin-top:50px;
       	width: 700px;
       	position: relative;
       }
       select{
       	width: 150px;
        height: 20px;
       	margin: 0 auto;
       	position: absolute;
       	left: 275px;
       }
       .input{
       	   width: 200px;

       }
      .span{
       	   display: inline-block;
       	   width: 90px;
       	   margin-top: 25px;
       }
       .moveright{
       	   margin-left: 30px;
       }
       textarea{
       	resize:none;
       	height:400px;
       	width:700px;   
       }
       .button{
       	   display: inline-block;
       	   margin-top: 30px;
       	   height: 28px;
       	   width: 80px;
       	   margin-right:15px;
       	   float:right;
       	   line-height: 25px;

       }
       .info{
          font-size: 13px;
          color: red;
          float: right;
          margin-right: 15px;
          position: relative;
          top:15px;
       }
    
</style>
</head>
<body>
	<form id="form">
          <select>
		           <option>文章模型</option>
		    	</select><br>
		     <span class="span">编辑：</span><input class="input" type="text" name="editor" id="editor">
		     <span class="span moveright">标题：</span><input class="input" type="text" name="title" id="title"><br>
		     <span class="span">来源：</span><input class="input" type="text" name="source" id="source">
		     <span class="span moveright">作者：</span><input class="input" type="text" name="author" id="author"><br>	    
		     <span class="span">内容：</span><br>
		     <textarea rols="10" rows="5" id="textarea" name="textarea"></textarea>
		     <span style="position:relative;top:15px;">赞次数：</span><input type="number" name="number" id="likeTimes" style="position:relative;top:15px;">
		     <span style="position:relative;top:15px;">状态：</span><input type="checkbox" name="checkbox" style="position:relative;top:15px;" id="status"><span class="info"></span><br>
		     <input type="button" class="button" id="submit" value="提交">
		     <a class="button" style="position:relative;left:20px;top:3px;" href="content_mag.html">返回</a>
	</form>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script charset="utf-8" src="js/kindeditor/lang/zh_CN.js"></script>
<script type="text/javascript" src="js/kindeditor/kindeditor-min.js"></script>
<script type="text/javascript" src="../public/js/serverIp.js"></script>
<script type="text/javascript">


        var editor;
        KindEditor.ready(function(K){
            	 K.create("#textarea",{
      				      uploadJson : 'js/kindeditor/php/upload_json.php', //指定上传图片的服务器端程序
      				      allowUpload : true,
      					    fileManagerJson:"jskindeditor/php/file_manager_json.php",
      					    allowFileManager : true,
      				      urlType : 'absolute',
      				      resizeType : 0,  //文本框不可拖动
  				        
    				        afterCreate : function(){ //kindeditor创建后，将编辑器的内容设置到原来的textarea控件里
    				               this.sync();   
    				        },
    				        afterChange: function(){ //编辑器内容发生变化后，将编辑器的内容设置到原来的textarea控件里
    				               this.sync();   
    				        },
    				        afterBlur : function(){ //编辑器聚焦后，将编辑器的内容设置到原来的textarea控件里
    				            this.sync(); 
    				        }  
    		       })

        })

        var array=window.location.href.split("?");
        var substr=array[1].split("&");
        var datastr="type=ID&bool=false&columnId="+substr[1]+"&modelId="+substr[0]+"&id="+substr[3];
        if(substr[2]=="edit"){
            $.post(serverIp+"/Scauaie.com/artical/showAll",datastr,function(data){
              
                  KindEditor.html('#textarea',data[0].content);//给文本框内赋值
                 $("#editor").val(data[0].editor);
                 $("#title").val(data[0].title);
                 $("#source").val(data[0].source);
                 $("#author").val(data[0].author);
                 $("#textarea").val(data[0].content);
                 $("#likeTimes").val(data[0].likeTimes);
                 data[0].status==true?$("#status").attr("checked",true):null;
            },"json")

        }

        function submitTo(url,id){

                    var arr=window.location.href.split("?");
                    var sub=arr[1].split("&");
                    var time="2016/4/14";
                    var editor=$("#editor").val();
                    var source=$("#source").val();
                    var title=$("#title").val();
                    var author=$("#author").val();
                    var content=$("#textarea").val();
                    var likeTimes=$("#likeTimes").val();
                    var status=$("#status").attr("checked")=="checked"?true:false;

                    var data={
                        "type":"COLUMN",
                        "bool":false,
                        "modelId":sub[0],
                        "columnId":sub[1],
                        "time":time,
                        "editor":editor,
                        "source":source,
                        "title":title,
                        "author":author,
                        "content":content,
                        "likeTimes":likeTimes,
                        "status":status,
                        "id":id

                    };

                   if(!source||!title||!author||!content||!likeTimes){
                          alert("请先填写完整");
                   }else{

                      $.post(url,{"data":JSON.stringify(data)},function(data){
                            var dataobj=JSON.parse(data);
                            if(dataobj.bool=="true"){
                                if(confirm("提交成功，留在本页面？")){
                                   var href=window.location.href;
                                   window.location.href=href;
                                }else{
                                   window.location.href="content_mag.html";
                                }
                            }else{
                               alert("提交失败，请重新尝试.")                          
                            } 

                       },"html")
                   }               
          }


         $("#submit").click(function(){

             if(substr[2]=="edit"){
                  submitTo(serverIp+"/Scauaie.com/artical/edit",substr[3]);

             }else{
                  submitTo(serverIp+"/Scauaie.com/artical/add",null);
             }  
          })
</script>
</body>
</html>	